package com.jingsong.studentapp.page;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.jingsong.studentapp.R;
import com.jingsong.studentapp.adapter.ExamAdapter;
import com.jingsong.studentapp.lister.OnItemEventListener;
import com.jingsong.studentapp.model.ExamModel;

import java.util.ArrayList;

/**
 * 考试
 */
public class ExamActivity extends AppCompatActivity implements OnItemEventListener, View.OnClickListener {
    private ExamAdapter<ExamModel> adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_exam);

        TextView tvTitle = findViewById(R.id.tvName);
        tvTitle.setText("考试");
        ImageView ivBack = findViewById(R.id.ivBack);
        ivBack.setOnClickListener(this);

        adapter = new ExamAdapter<>();
        adapter.setEventListener(this);
        RecyclerView rvList = findViewById(R.id.rcvList);
        rvList.setLayoutManager(new LinearLayoutManager(this));
        rvList.setAdapter(adapter);

        ArrayList<ExamModel> allItems = new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            ExamModel model = new ExamModel();
            model.name = "例行考试" + i;
            model.state = i % 3;
            model.times = "2021-12-10 10:10";
            allItems.add(model);
        }
        adapter.setDatas(allItems);
    }

    @Override
    public void onItemEvent(int pos) {
        startActivity(new Intent(ExamActivity.this, AppraisalActivity.class));
    }

    @SuppressLint("NonConstantResourceId")
    @Override
    public void onClick(View view) {
        if (view.getId() == R.id.ivBack) {
            finish();
        }
    }
}